package com.bjpowernode.java;

/**
 * @author wuyuecai
 * @create 2021-05-30 19:56
 */
public class Reversal {
    public static void main(String[] args) {

//        char[] chars = new char[]{'5','6','9','2','8'};
//        for (int i = 0; i < chars.length/2; i++) {
//            char temp = chars[i];
//            chars[i] = chars[chars.length-1-i];
//            chars[chars.length-1-i] = temp;
//        }
//        for (int i = 0; i < chars.length; i++) {
//            System.out.print(chars[i]+"\t");
//        }
        System.out.println(reverse(1534236469));
    }

    public static long reverse(long x) {


        boolean flag = false;
        if (x < 0) {
            flag = true;
            x = -x;
        }
        String s = String.valueOf(x);
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length / 2; i++) {
            char temp = chars[i];
            chars[i] = chars[chars.length - 1 - i];
            chars[chars.length - 1 - i] = temp;
        }
        String s1 = new String(chars);
        long num = Integer.parseInt(s1);
        if ( num <= -2147483648 || num >= 2147483647) {
            return 0;
        }
        if (flag) {
            return -num;
        }
        return num;

    }
}
